Repository navigation
Sanitize the datatable title, study name and related titles on the datatable page - #56
Merged
Merged
Conversation
The heading printed the title with raw, so markup in a title ran in the page. The page's <title> tag and breadcrumb already escape it. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016AR3uoZS1uCC8hXmojk3K7
Titles can carry simple formatting (N<sub>2</sub>O), so rather than showing the tags as text, the heading keeps sub, sup, em, i, strong and b without attributes and removes everything else, including scripts, links and event handlers. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016AR3uoZS1uCC8hXmojk3K7
It sits next to the title in the same heading and was still printed with raw. It gets the same rules: simple inline formatting kept, everything that could run removed. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016AR3uoZS1uCC8hXmojk3K7
They were printed with raw inside their links. They get the same rules as the heading: simple inline formatting kept, everything that could run removed. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016AR3uoZS1uCC8hXmojk3K7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
datatables/show.html.erbprinted a datatable's title, its study's name and its related tables' titles withraw, so markup in any of them ran in the page. (The page<title>and breadcrumb already escaped the title.) They now go through asanitized_titlehelper:sub,sup,em,i,strongandb, with no attributes, so a title likeN<sub>2</sub>O at 5°Cstill renders as formatted text. HTML entities display normally.javascript:URLs and every other tag. The text inside is kept.<h1>(title and study name) and the "Related Tables" links, which stay links.The helper is a one-line wrapper around Rails' own
sanitize(rails-html-sanitizer / Loofah) with a narrow tag list. It isn't a custom sanitizer. It exists so the list is in one place; the defaultsanitizeallowlist is wider than a title needs (links, images, headings, tables).The branch started as "escape the title" and became "sanitize" after discussion, so it has four commits. Squash on merge if you want one.
Before merging
Titles that deliberately contain other markup, such as links or line breaks, will lose it. I can't see production data; a quick check is:
Not changed
Still printed with
rawon this page: the embedded JSON-LD (line 3) and the Markdown-rendered description (line 27). They hold different content and need a different approach. About 16 otherraw/html_safeuses remain in the datatable and subdomain views.Testing
spec/requests/datatable_title_escaping_spec.rb: simple formatting and entities are kept; scripts, event handlers and links are removed from the title; the study name is sanitized; related-table titles are sanitized and stay links. Each fails against the old raw output.schema.rbbefore 7f502da, since master's current schema can't be loaded into a fresh database (see the structure.sql PR Dump the database schema as db/structure.sql #53).Generated by Claude Code